package mobi.hami.huapin.dao;

import java.util.List;

import mobi.hami.huapin.daobase.CrudMapper;
import mobi.hami.huapin.model.ProductShowAttribute;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface ProductShowAttributeMapper extends CrudMapper<ProductShowAttribute> {

    @Insert("<script> Insert into product_show_attribute(spu_id,\n" +
            "attribute_name,\n" +
            "attribute_value)Values \n" +
            "<foreach item='item' collection='productShowAttributes' separator=\",\"> " +
            " ( #{item.spu_id}," +
            " #{item.attribute_name}," +
            " #{item.attribute_value})" +
            "</foreach></script>")
    int insertList(@Param("productShowAttributes") List<ProductShowAttribute> productShowAttributes);

    @Delete("delete from product_show_attribute where  spu_id =#{spu_id}")
    int deleteAll(Integer spuid);

    @Select("select  * from product_show_attribute where  spu_id =#{spu_id}")
    List<ProductShowAttribute> selectProductAll(int spuid);


    /**
     * 用户前端查询
     * @param ids
     * @return
     */
    @Select("SELECT spu_id,attribute_name,attribute_value from product_show_attribute where spu_id in (${ids})  order by id asc ")
    public List<ProductShowAttribute> getListForUser(@Param("ids")String ids);

}